package com.ruoyi.web.controller.datastatistics;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.datastatistics.domain.DosageTrendData;
import com.ruoyi.datastatistics.service.ITerminalDbStatisticAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/datastatistics/terminalDbStatisticAnalysis")
public class TerminalDbStatisticAnalysisController extends BaseController {

    @Autowired
    private ITerminalDbStatisticAnalysisService terminalDbStatisticAnalysisService;

    /**
     * 一个表多时段
     */
    @GetMapping("/oneTerminal")
    public AjaxResult oneTerminal(@RequestParam(name = "location_nb", required = false) String[] location_nb,
                                  @RequestParam(name = "readDates", required = false) String[] readDates) {
        return success(terminalDbStatisticAnalysisService.oneTerminal(location_nb, readDates));
    }

    /**
     * 多表同时段
     */
    @GetMapping("/multiTerminal")
    public AjaxResult multiTerminal(@RequestParam(name = "location_nb", required = false) String[] location_nb,
                                    @RequestParam(name = "readDates", required = false) String[] readDates) {
        return success(terminalDbStatisticAnalysisService.multiTerminal(location_nb, readDates));
    }


    /**
     * 用量趋势
     */
    @GetMapping("/dosageTrend")
    public AjaxResult dataTrend(@RequestParam(name = "location_nb", required = true) String location_nb,
                                @RequestParam(name = "startTime", required = false) String startTime,
                                @RequestParam(name = "endTime", required = false) String endTime,
                                @RequestParam(name = "interval", required = false) String interval,
                                @RequestParam(name = "dataType", required = false) String dataType
    ) {
        return success(terminalDbStatisticAnalysisService.dosageTrend(location_nb, startTime, endTime, interval, dataType));
    }


    /**
     * 用量趋势
     */
    @GetMapping("/dataTrendForPage")
    public TableDataInfo dataTrendForPage(DosageTrendData dosageTrendData
    ) {
        String location_nb = dosageTrendData.getLocation_nb();
        String startTime = dosageTrendData.getStartTime();
        String endTime = dosageTrendData.getEndTime();
        String interval = dosageTrendData.getInterval();
        String dataType = dosageTrendData.getDataType();

        List<DosageTrendData> list = new ArrayList<>();
        switch (dataType) {
            //时报表
            case "1":
                Integer counts = terminalDbStatisticAnalysisService.dosageTrend(location_nb, startTime, endTime, interval, dataType).size();
                startPageNoCount();
                list = terminalDbStatisticAnalysisService.dosageTrend(location_nb, startTime, endTime, interval, dataType);
                return getDataTableNoCount(list, counts);
            //日报表
            case "2":
                startPage();
                list = terminalDbStatisticAnalysisService.dosageTrend(location_nb, startTime, endTime, interval, dataType);
                return getDataTable(list);
            //月报表
            case "3":
                startPage();
                list = terminalDbStatisticAnalysisService.dosageTrend(location_nb, startTime, endTime, interval, dataType);
                return getDataTable(list);
            default:
                return getDataTable(list);
        }

    }


}
